package vashion.azeroth.core.service.base;

import vashion.azeroth.core.pojo.BaseObject;

public class BaseService {

	protected Integer totalCounts; //总记录条数
	protected Integer pageSize;    //每页大小
	protected Integer totalPages;  //总页数
	protected Integer pageNum;     //当前的页

	protected boolean showFirst;   //是否显示首页
	protected boolean showLast;    //是否显示尾页
	protected boolean showNext;    //是否显示下一页
	protected boolean showPrevious;  //是否显示上一页

	public void initPages(BaseObject object,int totalCounts){
		this.pageSize = object.getPageSize();
		this.pageNum = object.getPageNum();
		this.totalCounts = totalCounts;
		totalPages = (totalCounts%pageSize == 0) ? totalCounts/pageSize : (totalCounts/pageSize + 1);
		if(totalPages > 0){ //当totalPages <=0时 表明没有任何记录 所有上一页 下一页  首页 末页标签取默认值 不显示
			pageNum = (pageNum<=0)?1:pageNum;
			pageNum = (pageNum>totalPages)?totalPages:pageNum;
			showFirst =(pageNum == 1)?false:true;
			showLast =(pageNum == totalPages)?false:true;
			showPrevious = (pageNum == 1)?false:true;
			showNext = (pageNum == totalPages)?false:true;
			object.setFirstRow(pageSize*(pageNum-1));
		}else{
			pageNum = 0;
		}
	}

	public Integer getTotalCounts() {
		return totalCounts;
	}

	public void setTotalCounts(Integer totalCounts) {
		this.totalCounts = totalCounts;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(Integer totalPages) {
		this.totalPages = totalPages;
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public boolean isShowFirst() {
		return showFirst;
	}

	public void setShowFirst(boolean showFirst) {
		this.showFirst = showFirst;
	}

	public boolean isShowLast() {
		return showLast;
	}

	public void setShowLast(boolean showLast) {
		this.showLast = showLast;
	}

	public boolean isShowNext() {
		return showNext;
	}

	public void setShowNext(boolean showNext) {
		this.showNext = showNext;
	}

	public boolean isShowPrevious() {
		return showPrevious;
	}

	public void setShowPrevious(boolean showPrevious) {
		this.showPrevious = showPrevious;
	}
}
